import {reqCategoryList,reqGetBannerList,reqFloorList} from '@/api'

const state = {
    categoryList:[], // 三级联动
    bannerList:[], // 轮播图
    floorList:[], // 楼层
}
const mutations = {
    CATEGORYLIST(state,categoryList){
        state.categoryList = categoryList
    },
    GETBANNERLIST(state,bannerList){
        state.bannerList = bannerList
    },
    GETFLOORLIST(state,floorList){
        state.floorList = floorList
    }
}
const actions = {
    // 通过 API 里面的接口函数调用，向服务器发请求，获取服务器数据
    async categoryList({commit}){
        const result =  await reqCategoryList()
        if(result.code == 200){
            commit('CATEGORYLIST', result.data)
        }
    },
    // 获取首页轮播图的数据
    async getBannerList({commit}){
        const result = await reqGetBannerList()
        if(result.code === 200){
            commit('GETBANNERLIST',result.data)
        }
    },
    // 获取首页楼层数据
    async getFloorList({commit}){
        const result = await reqFloorList()
        if(result.code === 200){
            commit('GETFLOORLIST',result.data)
        }
    }
}
export default {
    state,
    mutations,
    actions
}